import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/public_total.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_button.dart';
import '../cabinet_form_bottom_custom_check.dart';
import '../cabinet_form_bottom_custom_date.dart';
import 'logic.dart';

class CabinetFromBottomCustomPage extends StatefulWidget {
  final Function(String start, String end)? result;
  const CabinetFromBottomCustomPage({
    Key? key,
    this.result,
  }) : super(key: key);

  @override
  State<CabinetFromBottomCustomPage> createState() => _CabinetFromBottomCustomPageState();
}

class _CabinetFromBottomCustomPageState extends State<CabinetFromBottomCustomPage> {
  final CabinetFromBottomCustomLogic logic = Get.put(CabinetFromBottomCustomLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: MGColors.whileColor,
        body: Container(
          margin: EdgeInsets.all(20),
          child: Column(
            children: [
              CabinetFormBottomCustomCheck(
                selectAction: logic.selectCheck,
              ),
              SizedBox(height: 20),
              GetBuilder<CabinetFromBottomCustomLogic>(builder: (controller) {
                return CabinetFormBottomCustomDate(
                  startTime: controller.startTime,
                  endTime: controller.endTime,
                  selectAction: logic.selectDatePicker,
                );
              }),
            ],
          ),
        ),
        bottomNavigationBar: Container(
          margin: EdgeInsets.only(left: 20, right: 20, bottom: 40),
          child: Flex(
            direction: Axis.horizontal,
            children: [
              Expanded(
                  child: MGButton(
                title: "重置",
                buttonBackColor: MGColors.backColor,
                buttonAction: logic.reset,
              )),
              SizedBox(width: 20),
              Expanded(
                  child: MGButton(
                title: "确认",
                buttonAction: () {
                  if (logic.startTime.isEmpty) {
                    HLTotal.total("请选择开始时间");
                    return;
                  }
                  if (logic.endTime.isEmpty) {
                    HLTotal.total("请选择结束时间");
                    return;
                  }
                  if (widget.result != null) {
                    widget.result!(logic.startTime, logic.endTime);
                    Get.back();
                  }
                },
              ))
            ],
          ),
        ));
  }

  @override
  void dispose() {
    Get.delete<CabinetFromBottomCustomLogic>();
    super.dispose();
  }
}
